$().ready(function(e) {
    signup.init();
});
var signup = {
	init: function(){
		$('#doSignup').submit(function(){
			$('button.doSignUpBtn').attr('disabled',true);
			setTimeout(function(){
				signup.doSignUp();
			},3000);
		});
	},
	doSignUp: function(){
		var strUserName = $('#strUserName').val();
		var strEmail = $('#strEmail').val();
		var strFirstName = $('#strFirstName').val();
		var strLastName = $('#strLastName').val();
		var strPassword1 = $('#strPassword1').val();
		var strPassword2 = $('#strPassword2').val();
		var strGender = $('input[type="radio"]:checked').val();
		
		uri = 'register/do_register';
		data = {
			'strUserName' : strUserName,
			'strEmail' : strEmail,
			'strFirstName' : strFirstName,
			'strLastName' : strLastName,
			'strPassword1' : strPassword1,
			'strPassword2' : strPassword2,
			'strGender' : strGender
		};
		$.ajax({
			type: "POST",
			url: base_url+uri,
			data: data,
			dataType: 'json',
			success: function(result){
				msg = '';
				if(result.status == 'put_username'){
					msg += '<div class="alert alert-warning">';
						msg += '<i class="glyphicon glyphicon-exclamation-sign"></i> Please put your username.';
					msg += '</div>';
				} else if(result.status == 'put_firstname') {
					msg += '<div class="alert alert-warning">';
						msg += '<i class="glyphicon glyphicon-exclamation-sign"></i> Please put your firstname.';
					msg += '</div>';
				} else if(result.status == 'put_lastname') {
					msg += '<div class="alert alert-warning">';
						msg += '<i class="glyphicon glyphicon-exclamation-sign"></i> Please put your lastname.';
					msg += '</div>';
				} else if(result.status == 'put_email') {
					msg += '<div class="alert alert-warning">';
						msg += '<i class="glyphicon glyphicon-exclamation-sign"></i> Please put your e-amail address.';
					msg += '</div>';
				} else if(result.status == 'put_password') {
					msg += '<div class="alert alert-warning">';
						msg += '<i class="glyphicon glyphicon-exclamation-sign"></i> Please put your password.';
					msg += '</div>';
				} else if(result.status == 'retype_password') {
					msg += '<div class="alert alert-warning">';
						msg += '<i class="glyphicon glyphicon-exclamation-sign"></i> Please re-type your password.';
					msg += '</div>';
				} else if(result.status == 'pw_mismatch') {
					msg += '<div class="alert alert-warning">';
						msg += '<i class="glyphicon glyphicon-exclamation-sign"></i> Password mis-matched.';
					msg += '</div>';
				} else if(result.status == 'username_exist') {
					msg += '<div class="alert alert-warning">';
						msg += '<i class="glyphicon glyphicon-exclamation-sign"></i> Username is already taken.';
					msg += '</div>';
				} else if(result.status == 'email_exist') {
					msg += '<div class="alert alert-warning">';
						msg += '<i class="glyphicon glyphicon-exclamation-sign"></i> E-mail address is already in use.';
					msg += '</div>';
				} else if(result.status == 'email_not_valid') {
					msg += '<div class="alert alert-warning">';
						msg += '<i class="glyphicon glyphicon-exclamation-sign"></i> E-mail address is invalid.';
					msg += '</div>';
				} else {
					msg += '<div class="alert alert-success">';
						msg += '<i class="glyphicon glyphicon-ok-sign"></i> Your account was successfully created. Check your email inbox and verify your account.';
					msg += '</div>';
				}
				$('.msgHolder').html(msg);
				$('button.doSignUpBtn').attr('disabled',false);
				setTimeout(function(){
					$('.alert').fadeOut('slow');	
				},3000);
			}
		});
	}
}